<?php
include('../data/comm.inc.php');
include('../data/mobivar.php');
include('../func/func.php');
include('../func/csfunc.php');

include('../func/userfunc.php');
include('../include.php');
include('./checklogin.php');

switch($_REQUEST['xtype']){
   case "kj":
		$tpl->assign('title', $config['webname'] );
        $tpl->assign('gid', $gid);
        $gamecs = getgamecs($userid);
        $gamecs = getgamename($gamecs);
		$tpl->assign('gamecs', $gamecs);
		$tpl->display("kj.html");
   break;
   case "getkj":
      include("../func/jsfunc.php");
      $gid = $_POST['gid'];
	  $mnum = transgame($gid,'mnum');
	  $psize = $config['psize2'];
	  $tpage = rpage($_POST['tpage']);
	  
	  $msql->query("select count(id) from `x_kj` where gid='$gid' ");
	  $msql->next_record();
	  $rcount = pr0($msql->f(0));
	  $kj=array();
	  $i=0;
	  $time=sqltime(time());
	  
	  $sql = "select * from `x_kj` where gid='$gid' and kjtime<='$time' order by qishu desc limit ".(($tpage-1)*$psize).",".$psize;
	  $msql->query($sql);
	  while($msql->next_record()){
		 if(in_array($gid,array(161,162,163,107))){
	        $kj[$i]['qishu'] = $msql->f('qishu');
		 }else{
		    $kj[$i]['qishu'] = substr($msql->f('qishu'),-3);
		 }
		 $kj[$i]['kjtime'] = date("H:i",$msql->f('kjtime'));
		 $hs = 0;
		 for($j=1;$j<=$mnum;$j++){
	        $kj[$i]['m'][$j-1] = $msql->f("m".$j);
			if($gid!=107) $hs += $msql->f("m".$j);
		 }
		 if($gid==107) $hs =  $msql->f("m1")+$msql->f("m2");
		 $kj[$i]['hs'] = $hs;
		 $kj[$i]['ds'] = ds($gid,$hs);
		 $kj[$i]['dx'] = zhdx($gid,$hs);
		 $i++;
	  }
	  echo json_encode(array("kj"=>$kj,"rcount"=>$rcount,"mnum"=>$mnum,"psize"=>$psize,"sql"=>$sql));
	  unset($kj);

   break;
}
?>